package com.tianji.promotion.config;

import com.tianji.promotion.utils.MyLockAspect;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

@Configuration
@Slf4j
public class PromotionConfig {

    @Bean
    public Executor generateExchangeCodeExecutor(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //1.核心线程池的大小
        executor.setCorePoolSize(2);
        //2.最大线程数
        executor.setMaxPoolSize(5);
        //3.队列大小
        executor.setQueueCapacity(200);
        //4.线程名字的前缀
        executor.setThreadNamePrefix("generate-code-handler-");
        //5.拒绝策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }

    @Bean
    public Executor discountSolutionExecutor(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //1.核心线程池的大小
        executor.setCorePoolSize(12);
        //2.最大线程数
        executor.setMaxPoolSize(12);
        //3.队列大小
        executor.setQueueCapacity(99999);
        //4.线程名字的前缀
        executor.setThreadNamePrefix("discount-solution-calculate");
        //5.拒绝策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
        executor.initialize();
        return executor;
    }


}
